{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "\n",
    "---\n",
    "个人信息:  \n",
    "- 姓名: 石庆波\n",
    "- 年级: 2020\n",
    "- 专业: 智能科学与技术\n",
    "- 班级: 一班\n",
    "---\n",
    "\n",
    "- 诚信守则:  \n",
    "    - 我承诺该报告内容**为我个人书写非直接抄袭所得。**\n",
    "    - 我**可以解释答题思路并复现我的答案。**\n",
    "    - 如无法实现以上要求，**我愿意承担由此带来的后果。**\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#  多维数组的索引和切片"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 引入适当的模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from tabulate import tabulate"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "###  生成[0,88]范围内的所有偶数,  设置结构为3 * 5 * 3模式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = np.arange(0, 89, 2).reshape((3,5,3))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 按照习题要求页面的结果生成指定的数组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "a1 = a[1, 2, 2]\n",
    "a2 = a[1:2, 2:3, 2: ]\n",
    "a3 = a[1, 1]\n",
    "a4 = a[1:2, 1:2]\n",
    "a5 = a[:, 3 , :]\n",
    "a6 = a[ : , 3:4]\n",
    "a7 = a[1: , 3: , 1]\n",
    "a8 = a[ : ,-1::-2 ]\n",
    "\n",
    "result=[\n",
    "        ['array','ndim','shape','result'],\n",
    "        ['a',a.ndim,a.shape,tabulate(a,tablefmt='grid')],\n",
    "        ['a1',a1.ndim,a1.shape,a1],\n",
    "        ['a2',a2.ndim,a2.shape,tabulate(a2,tablefmt='grid')],\n",
    "        ['a3',a3.ndim,a3.shape,a3],\n",
    "        ['a4',a4.ndim,a4.shape,tabulate(a4,tablefmt='grid')],\n",
    "        ['a5',a5.ndim,a5.shape,tabulate(a5,tablefmt='grid')],\n",
    "        ['a6',a6.ndim,a6.shape,tabulate(a6,tablefmt='grid')],\n",
    "        ['a7',a7.ndim,a7.shape,tabulate(a7,tablefmt='grid')],\n",
    "        ['a8',a8.ndim,a8.shape,tabulate(a8,tablefmt='grid')]\n",
    "]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 显示结果,  请把答案写在一行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "+---------+--------+-----------+--------------------------------------------------------------------+\n",
      "| array   |   ndim | shape     | result                                                             |\n",
      "+=========+========+===========+====================================================================+\n",
      "| a       |      3 | (3, 5, 3) | +------------+------------+------------+------------+------------+ |\n",
      "|         |        |           | | [0 2 4]    | [ 6  8 10] | [12 14 16] | [18 20 22] | [24 26 28] | |\n",
      "|         |        |           | +------------+------------+------------+------------+------------+ |\n",
      "|         |        |           | | [30 32 34] | [36 38 40] | [42 44 46] | [48 50 52] | [54 56 58] | |\n",
      "|         |        |           | +------------+------------+------------+------------+------------+ |\n",
      "|         |        |           | | [60 62 64] | [66 68 70] | [72 74 76] | [78 80 82] | [84 86 88] | |\n",
      "|         |        |           | +------------+------------+------------+------------+------------+ |\n",
      "+---------+--------+-----------+--------------------------------------------------------------------+\n",
      "| a1      |      0 | ()        | 46                                                                 |\n",
      "+---------+--------+-----------+--------------------------------------------------------------------+\n",
      "| a2      |      3 | (1, 1, 1) | +----+                                                             |\n",
      "|         |        |           | | 46 |                                                             |\n",
      "|         |        |           | +----+                                                             |\n",
      "+---------+--------+-----------+--------------------------------------------------------------------+\n",
      "| a3      |      1 | (3,)      | [36 38 40]                                                         |\n",
      "+---------+--------+-----------+--------------------------------------------------------------------+\n",
      "| a4      |      3 | (1, 1, 3) | +------------+                                                     |\n",
      "|         |        |           | | [36 38 40] |                                                     |\n",
      "|         |        |           | +------------+                                                     |\n",
      "+---------+--------+-----------+--------------------------------------------------------------------+\n",
      "| a5      |      2 | (3, 3)    | +----+----+----+                                                   |\n",
      "|         |        |           | | 18 | 20 | 22 |                                                   |\n",
      "|         |        |           | +----+----+----+                                                   |\n",
      "|         |        |           | | 48 | 50 | 52 |                                                   |\n",
      "|         |        |           | +----+----+----+                                                   |\n",
      "|         |        |           | | 78 | 80 | 82 |                                                   |\n",
      "|         |        |           | +----+----+----+                                                   |\n",
      "+---------+--------+-----------+--------------------------------------------------------------------+\n",
      "| a6      |      3 | (3, 1, 3) | +------------+                                                     |\n",
      "|         |        |           | | [18 20 22] |                                                     |\n",
      "|         |        |           | +------------+                                                     |\n",
      "|         |        |           | | [48 50 52] |                                                     |\n",
      "|         |        |           | +------------+                                                     |\n",
      "|         |        |           | | [78 80 82] |                                                     |\n",
      "|         |        |           | +------------+                                                     |\n",
      "+---------+--------+-----------+--------------------------------------------------------------------+\n",
      "| a7      |      2 | (2, 2)    | +----+----+                                                        |\n",
      "|         |        |           | | 50 | 56 |                                                        |\n",
      "|         |        |           | +----+----+                                                        |\n",
      "|         |        |           | | 80 | 86 |                                                        |\n",
      "|         |        |           | +----+----+                                                        |\n",
      "+---------+--------+-----------+--------------------------------------------------------------------+\n",
      "| a8      |      3 | (3, 3, 3) | +------------+------------+------------+                           |\n",
      "|         |        |           | | [24 26 28] | [12 14 16] | [0 2 4]    |                           |\n",
      "|         |        |           | +------------+------------+------------+                           |\n",
      "|         |        |           | | [54 56 58] | [42 44 46] | [30 32 34] |                           |\n",
      "|         |        |           | +------------+------------+------------+                           |\n",
      "|         |        |           | | [84 86 88] | [72 74 76] | [60 62 64] |                           |\n",
      "|         |        |           | +------------+------------+------------+                           |\n",
      "+---------+--------+-----------+--------------------------------------------------------------------+\n"
     ]
    }
   ],
   "source": [
    "print(tabulate(result, headers='firstrow', tablefmt='grid'))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
